<?php
define(ERR_INIT_OK, 0);
define(ERR_LOAD_OK, 1);
define(ERR_CONNECTFAILED, -1);
define(KEY_BASIC, "basic");
define(KEY_ITEMS, "items");
define(KEY_SKILLS, "skills");

// SUBKEY_BASIC_
define(SUBKEY_BASIC_EMAIL, "email");
define(SUBKEY_BASIC_FAMELEVEL, "famelevel");
define(SUBKEY_BASIC_FAMEPOINT, "famepoint");
define(SUBKEY_BASIC_AQ, "AQ");
define(SUBKEY_BASIC_IQ, "IQ");
define(SUBKEY_BASIC_EQ, "EQ");
define(SUBKEY_BASIC_CQ, "CQ");
define(SUBKEY_BASIC_GOLD, "gold");
define(SUBKEY_BASIC_ENERGY, "energy");
	
class XXXSNS {

	function userLogin($email) {
		$error_code = ERR_LOAD_OK;
		$result = Array();
		$memcache = new Memcache();

		if($memcache->connect('localhost', 11211)) {
			$key_basic = $email . "\\" . KEY_BASIC;
			$key_items = $email . "\\" . KEY_ITEMS;
			$key_skills = $email . "\\" . KEY_SKILLS;
			$user_basic = $memcache->get($key_basic);
			if($user_basic) {
				$user_items = $memcache->get($key_items);
				$user_skills = $memcache->get($key_skills);
			}
			else {
				$error_code = ERR_INIT_OK;
				$user_basic = Array();
				$user_items = Array();
				$user_skills = Array();
				
				$user_basic[SUBKEY_BASIC_EMAIL] 		= $email;
				$user_basic[SUBKEY_BASIC_FAMELEVEL] 	= 1;
				$user_basic[SUBKEY_BASIC_FAMEPOINT] 	= 0;
				$user_basic[SUBKEY_BASIC_AQ] 			= 0;
				$user_basic[SUBKEY_BASIC_IQ] 			= 0;
				$user_basic[SUBKEY_BASIC_EQ] 			= 0;
				$user_basic[SUBKEY_BASIC_CQ] 			= 0;
				$user_basic[SUBKEY_BASIC_GOLD] 			= 5000;
				$user_basic[SUBKEY_BASIC_ENERGY] 		= 100;
				$memcache->set($key_basic, $user_basic);
			}
			
			$result[KEY_BASIC] = $user_basic;
			$result[KEY_ITEMS] = $user_items;
			$result[KEY_SKILLS] = $user_skills;
		}
		else {
			$error = ERR_CONNECTFAILED;
		}
		
		$ret = array("error_code" => $error_code, "result" => $result);
		return $ret;
	}
}